package com.lxp.project.system.service.impl;

import com.lxp.project.system.domain.SysRoleDept;
import com.lxp.project.system.mapper.SysRoleDeptMapper;
import com.lxp.project.system.service.ISysRoleDeptService;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
public class SysRoleDeptServiceImpl extends ServiceImpl<SysRoleDeptMapper, SysRoleDept> implements ISysRoleDeptService {
    @Override
    public void deleteRoleDeptByRoleId(Long roleId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq(SysRoleDept::getRoleId, roleId);
        this.mapper.deleteByQuery(wrapper);
    }

    @Override
    public void deleteRoleDept(Long[] roleIds) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in(SysRoleDept::getRoleId, Arrays.asList(roleIds));
        this.mapper.deleteByQuery(wrapper);
    }

    @Override
    public long selectCountRoleDeptByDeptId(Long deptId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq(SysRoleDept::getDeptId, deptId);
        return this.count(wrapper);
    }

    @Override
    @Transactional
    public int batchRoleDept(List<SysRoleDept> roleDeptList) {
        return this.saveBatch(roleDeptList) ? roleDeptList.size() : 0;
    }
}
